import {noAuth} from '../noAuth'

export const getTable = () => {
  return noAuth.get('/dev/table')
}

export const getField = (id) => {
  return noAuth.get(`/dev/table/${id}`)
}

export const getUnitCategory = () => {
  return noAuth.get('/dev/unit_category')
}

export const updateField = ({id, filedName, fieldType, type, description, regularExpression}) => {
  return noAuth.put('/dev/field', {
    id,
    filedName,
    fieldType,
    description,
    regularExpression,
    unit_category_id: type
  })
}

export const initTableAndField = () => {
  return noAuth.post('/dev/init')
}

export const addDict = (dictName) => {
  return noAuth.post('/dev/dict', {
    name: dictName
  })
}

export const addCategory = ({name, value}) => {
  return noAuth.post('/dev/category', {
    unitName: name,
    internationalUnits: value
  })
}

export const getDictLevel1 = () => {
  return noAuth.get('/dev/dict/level1')
}

export const addDictLevel2 = (dictLevel1Code, dictLevel2Name) => {
  return noAuth.post(`/dev/dict/${dictLevel1Code}`, {
    name: dictLevel2Name
  })
}

export const addCategoryValue = (categoryId, categoryValue) => {
  return noAuth.post(`/dev/category/${categoryId}`, {
    unitName: categoryValue
  })
}
